package com.woniu.sharepark.leasesystem.common.service.impl;/**
 * @Author litong
 * @Date 2019/6/4 10:37
 */

import com.woniu.sharepark.common.JsonResult;
import com.woniu.sharepark.common.pojo.Login;
import com.woniu.sharepark.leasesystem.common.dao.CarParkCommentReplyDAO;
import com.woniu.sharepark.common.dao.UserInfoDAO;
import com.woniu.sharepark.leasesystem.common.pojo.CarParkCommentReply;
import com.woniu.sharepark.leasesystem.common.service.CarParkCommentReplyService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 *@ClassName CarParkCommentReplyImpl
 *@Description 车位评论模块中回复功能的实现类
 *@Author litong
 *@Date 2019/6/4 10:37
 *@Version 1.0
 **/
@Service
public class CarParkCommentReplyImpl implements CarParkCommentReplyService {
    @Autowired
    private CarParkCommentReplyDAO carParkCommentReplyDAO;
    @Autowired
    private UserInfoDAO userInfoDAO;
    @Override
    public List<CarParkCommentReply> findAllReplysByCpcId(Integer cpcId) {
        return carParkCommentReplyDAO.queryReplysByCpcId(cpcId);
    }

    @Override
    public JsonResult addReply(CarParkCommentReply carParkCommentReply) {
        if (carParkCommentReply.getCpcrContent()==null||carParkCommentReply.getCpcrContent().equals("")){
            return JsonResult.error("恢复失败,回复内容不能为空");
        }
        Session session  = SecurityUtils.getSubject().getSession();
        Login login = (Login) session.getAttribute("currentUser");
        int cpcrTo=login.getUserInfo().getuId();
        //int cpcrTo=carParkCommentReply.getCpcrTo();
        String cpcrTname=userInfoDAO.selectUNameByUId(cpcrTo);
        //设置回复方姓名
        carParkCommentReply.setCpcrTo(cpcrTo);
        carParkCommentReply.setCpcrTname(cpcrTname);
        int cpcrBy=carParkCommentReply.getCpcrBy();
        String cpcrBname=userInfoDAO.selectUNameByUId(cpcrBy);
        //设置被回复方姓名
        carParkCommentReply.setCpcrBname(cpcrBname);
        //设置回复时间
        carParkCommentReply.setCpcrTime(new Date());
        carParkCommentReplyDAO.addReply(carParkCommentReply);
        return JsonResult.ok("回复成功");
    }

    @Override
    public JsonResult deleteReply(Integer cpcrId) {
        System.out.println(cpcrId);
        carParkCommentReplyDAO.deleteReply(cpcrId);
        return JsonResult.ok("撤回成功");
    }
}
